package com.vf.admin.miaodong.dao;

import com.vf.admin.common.db.BaseDao;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.AppCommentReply;
import com.vf.admin.miaodong.entity.AppFeedback;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * 反馈举报
 */
@Repository
public class AfterFeedbackDao extends BaseDao<AppFeedback> {

    /**
     * 查询列表
     */
    public List<AppFeedback> findList(Map<String,Object> paraMap, SplitPageBean splitPage) {
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_feedback where 1=1  ");
        if (StringEx.isNotNull(paraMap.get("nick"))) {
            sbStr.append(" and nick like ? ");
            paramList.add("%" + paraMap.get("nick") + "%");
        }
        if (StringEx.isNotNull(paraMap.get("phone"))) {
            sbStr.append(" and phone like ? ");
            paramList.add("%" + paraMap.get("phone") + "%");
        }
        if (StringEx.isNotNull(paraMap.get("leixing"))) {
            sbStr.append(" and leixing = ? ");
            paramList.add(paraMap.get("leixing") );
        }
        if (StringEx.isNotNull(paraMap.get("state"))) {
            sbStr.append(" and state = ? ");
            paramList.add(paraMap.get("state") );
        }
        if (StringEx.isNotNull(paraMap.get("userid"))) {
            sbStr.append(" and userid like ? ");
            paramList.add("%" + paraMap.get("userid") + "%" );
        }
        if (!StringEx.isNull(paraMap.get("startDate"))) {
            sbStr.append(" and createtime>=? ");
            paramList.add(paraMap.get("startDate"));
        }
        if (!StringEx.isNull(paraMap.get("endDate"))) {
            sbStr.append(" and createtime<=? ");
            paramList.add(paraMap.get("endDate"));
        }
        sbStr.append(" order by createtime desc ");
        String sql = sbStr.toString();
        return this.queryList(sql,paramList, AppFeedback.class,splitPage);
    }


    /**
     * 详情
     */
    public AppFeedback get(Integer id) {
        if (StringEx.isNullOrLing(id)) {
            return null;
        }
        List<Object> paramList = new ArrayList<Object>();
        StringBuilder sbStr = new StringBuilder("select * from app_feedback where 1=1");
        sbStr.append(" and id = ? ");
        paramList.add(id);
        String sql = sbStr.toString();
        return this.queryObj(sql, paramList, AppFeedback.class);
    }

    /**
     * 添加/修改
     */
    public void save(AppFeedback haoYou) {
        if (haoYou.getId() != null && haoYou.getId() > 0) {
            this.update(haoYou);
        } else {
            haoYou.setId(this.add(haoYou));
        }
    }

    /**
     * 删除
     */
    public void del(Integer id) {
        if (id <= 0) {
            return;
        }
        String sql = "delete  from app_feedback where id = ?";
        ArrayList<Object> paramList = new ArrayList<Object>();
        paramList.add(id);
        this.del(sql, paramList);
    }

    /**
     * 状态处理改变
     */
    public void chuli(Integer id,String remark) {
        if(id==null || id<=0){
            return ;
        }
        ArrayList<Object> paramList = new ArrayList<Object>();
        StringBuilder sbSql = new StringBuilder("UPDATE app_feedback SET state = 2, clcontrent = ?  WHERE id = ?  ");
        paramList.add(remark);
        paramList.add(id);
        String sql = sbSql.toString();
        this.update(sql, paramList);
    }
}
